<template>
  <div>
    <van-nav-bar
      title="注册"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
  </div>
  <div>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="rpassword"
          type="rpassword"
          name="重复密码"
          label="重复密码"
          placeholder="重复密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="nickname"
          name="用户昵称"
          label="用户昵称"
          placeholder="用户昵称"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
      </van-cell-group>

      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit">
          注册
        </van-button>
        <p @click="tologin">已有账号?点我登录吧</p>
      </div>
    </van-form>
  </div>
</template>
<script setup>
import http from "@/utils/http";
import { ref } from "vue";
import router from "@/router";

const onClickLeft = () => history.back();
const username = ref("");
const password = ref("");
const rpassword = ref("");
const nickname = ref("");
const onSubmit = (values) => {
  console.log("submit", values);
  http({
    url: "",
    method: "post",
    data: {
      username: username.value,
      password: password.value,
      rpassword: rpassword.value,
      nickname: nickname.value,
    },
  }).then((v) => {
    console.log(v);
    if (v.data.code == 1) {
      location.href = "/LoginView";
    }
  });
};
function tologin() {
  router.push("/Login");
}
</script>
<style lang=""></style>
